package com.cn.kehong.controller;


import com.cn.kehong.api.IDbBackService;
import com.cn.kehong.domain.DbBack;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/dbBack")
public class DbBackController {

    @Autowired
    private IDbBackService dbBackService;

    @RequestMapping("/queryDbBackList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<DbBack>> queryDbBackList(QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<DbBack>> response = new JsonResponse<List<DbBack>>();
        List<DbBack> list  = dbBackService.queryDbBackList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @ResponseBody
    @RequestMapping("/updateDbBack/{frontToken}")
    public JsonResponse<String> updateDbBack(@RequestBody DbBack dbBack, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = dbBackService.updateDbBack(dbBack);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/deleteDbBack/{frontToken}")
    public JsonResponse<String> deleteDbBack(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = dbBackService.deleteDbBack(queryForm);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/addDbBack/{frontToken}")
    public JsonResponse<String> addDbBack(@RequestBody DbBack dbBack, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = dbBackService.addDbBack(dbBack);
        return CommonUtil.getResponseData(response,result);
    }
}
